package com.atguigu.gmall.list.service.impl;

import com.atguigu.gmall.list.dao.GoodsDao;
import com.atguigu.gmall.list.service.GoodsService;
import com.atguigu.gmall.model.list.Goods;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author A
 * @version 1.0
 * @description: TODO
 * @date 2025/9/6 20:26
 */
@Slf4j
@Service
public class GoodsServiceImpl implements GoodsService {
    @Autowired
    private GoodsDao goodsDao;
    @Override
    public void saveGoods(Goods goods) {
        goodsDao.save(goods);
    }

    @Override
    public void deleteGoods(Long skuId) {
        goodsDao.deleteById(skuId);
    }

    @Override
    public void updateScore(Long skuId, Long score) {
        Optional<Goods> goods = goodsDao.findById(skuId);
        goods.ifPresent(g->{
            g.setHotScore(score);
            goodsDao.save(g);
            log.info("更新商品：{}的热度评分为：{}",skuId,score);
        });
    }
}
